﻿#If SILVERLIGHT Then
Namespace Web
#End If

Partial Public Class LLibreCaixa
    Public ReadOnly Property EsTancat As Boolean
        Get
            Return DataHoraTancament.HasValue
        End Get
    End Property

    Public ReadOnly Property TotalCalculat As Double
        Get
            Dim Resultat As Double = 0

            Resultat = Resultat + If(Me.CaixaInicial, 0)
            Resultat = Resultat + If(Me.TotalCash, 0)
            Resultat = Resultat + If(Me.TotalIngressos, 0)
            Resultat = Resultat - If(Me.Sobre, 0)
            Resultat = Resultat - If(Me.TotalDespeses, 0)

            Return Resultat
        End Get
    End Property

    Public ReadOnly Property TotalCash As Double?
        Get
            Dim Resultat As Double? = Nothing

#If SILVERLIGHT Then
#Else
            If Not Me.Reserva.IsLoaded Then Me.Reserva.Load()
#End If

            For Each Reserva As Reserva In (From R As Reserva In Me.Reserva Where R.IdTipusPagament = EnumTipusPagament.Cash)
                Resultat = If(Resultat, 0) + Reserva.Import
            Next

            Return Resultat
        End Get
    End Property

    Public ReadOnly Property TotalTargeta As Double?
        Get
            Dim Resultat As Double? = Nothing

#If SILVERLIGHT Then
#Else
            If Not Me.Reserva.IsLoaded Then Me.Reserva.Load()
#End If

            For Each Reserva As Reserva In (From R As Reserva In Me.Reserva Where R.IdTipusPagament = EnumTipusPagament.Targeta)
                Resultat = If(Resultat, 0) + Reserva.Import
            Next

            Return Resultat
        End Get
    End Property

    Public ReadOnly Property TotalDespeses As Double?
        Get
            Dim Resultat As Double? = Nothing

#If SILVERLIGHT Then
#Else
            If Not Me.LLibreCaixaDespesaIngres.IsLoaded Then Me.LLibreCaixaDespesaIngres.Load()
#End If

            For Each Despesa As LLibreCaixaDespesaIngres In (From DI As LLibreCaixaDespesaIngres In Me.LLibreCaixaDespesaIngres Where DI.EsDespesa)
                Resultat = If(Resultat, 0) + Despesa.Import
            Next

            Return Resultat
        End Get
    End Property

    Public ReadOnly Property TotalIngressos As Double?
        Get
            Dim Resultat As Double? = Nothing

#If SILVERLIGHT Then
#Else
            If Not Me.LLibreCaixaDespesaIngres.IsLoaded Then Me.LLibreCaixaDespesaIngres.Load()
#End If

            For Each Despesa As LLibreCaixaDespesaIngres In (From DI As LLibreCaixaDespesaIngres In Me.LLibreCaixaDespesaIngres Where Not DI.EsDespesa)
                Resultat = If(Resultat, 0) + Despesa.Import
            Next

            Return Resultat
        End Get
    End Property

    Public ReadOnly Property Diferencial As Double
        Get
            Dim Resultat As Double = 0

            Resultat = Resultat + If(CaixaFinal, 0)
            Resultat = Resultat - TotalCalculat

            Return Resultat
        End Get
    End Property
End Class

#If SILVERLIGHT Then
End Namespace
#End If
